const initialState = {

  arrslist: [],
  arsrds:[],
}

export default (state = initialState, {
  type,
  payload
}) => {

  let newState = JSON.parse(JSON.stringify(state))
  switch (type) {
    // 赋值数据
    case 'attlist':
      newState.arrslist = payload


      return newState

    case 'add':
      // let cartdataList =  window.localStorage.getItem('data')
      // newState.list = cartdataList
      newState.arrslist.unshift(payload)
      window.localStorage.setItem('data', JSON.stringify(newState.arrslist))

      return newState
// 查看
        case 'chakan':
          newState.arsrds = payload
          window.localStorage.setItem('data', JSON.stringify( newState.arsrds ))

    console.log(payload);
      return newState


       case 'operation':
        console.log(newState.arsrds);
        newState.arsrds.forEach((item ,index) => {
          if (item.id === payload.id) {
            newState.arsrds[index] = { ...payload }
            
          }
      })
      
    console.log(payload);
      return newState

      case 'edit_inp':
        
        newState.arsrds.forEach((item ,index) => {
          if (item.id === payload.id) {
            newState.arsrds[index] = { ...payload }
            // newState.arsrds[index].id = payload.id
          }
      })
      
    console.log(payload);
      return newState
    default:
      return state
  }
}